<?php

namespace App\Http\Controllers\Api;

use App\Exceptions\ServiceException;
use App\Http\Constants\CommonExceptionConstants;
use App\Http\Controllers\Controller;
use App\Util\ResultsVo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class DemoController extends Controller
{

    public function __construct()
    {
    }

    public function dat(Request $request) {
        #$data = $request->getContent();
        $data = $request->get('sign');
        file_put_contents(storage_path('dat.txt'), $data, FILE_APPEND);
    }

    public function success() {
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }

    public function fail() {
        throw new ServiceException(CommonExceptionConstants::getKey('no_find_data'));
    }

    public function result() {
        $data = [
            0 => ['id'=>1,'name'=>'食品','date'=>'2019-04-03'],
            1 => ['id'=>2,'name'=>'服装','date'=>'2019-04-02'],
            2 => ['id'=>3,'name'=>'鞋子','date'=>'2019-04-01'],
            3 => ['id'=>4,'name'=>'帽子','date'=>'2019-04-01'],
        ];
        return response()->json(new ResultsVo(['data'=>$data]));
    }

    public function page() {
        $data = [
            0 => ['id'=>1,'name'=>'食品','date'=>'2019-04-03'],
            1 => ['id'=>2,'name'=>'服装','date'=>'2019-04-02'],
            2 => ['id'=>3,'name'=>'鞋子','date'=>'2019-04-01'],
        ];
        return response()->json(new ResultsVo(['data'=>$data,'count'=>4]));
    }

}